package com.base.lib.util;

import android.content.Context;

import androidx.core.content.ContextCompat;

import com.afollestad.materialdialogs.MaterialDialog;
import com.base.lib.R;

import java.io.Serializable;

/**
 * @author neo.duan
 * @date 2018/07/09
 * @desc 弹出对话框工具类：show方法都带左边取消按钮，showSingleButton没有左边取消按钮
 */
public class MaterialDialogUtils implements Serializable {

    /**
     * 弹出单选按钮对话框
     */
    public static void showSingleButton(Context context, String content,
                                        MaterialDialog.SingleButtonCallback positiveCallBack) {
        showSingleButton(context, content, "确定", positiveCallBack);
    }

    /**
     * 弹出单选按钮对话框
     */
    public static void showSingleButton(Context context, String content, String positiveText,
                                        MaterialDialog.SingleButtonCallback positiveCallBack) {
        show(context, content, "", null, positiveText, positiveCallBack);
    }

    /**
     * 弹出单选按钮对话框
     */
    public static void show(Context context, String content, MaterialDialog.SingleButtonCallback positiveCallBack) {
        show(context, content, "确定", positiveCallBack);
    }

    /**
     * 弹出带取消按钮的对话框
     */
    public static void show(Context context, String content, String positiveText,
                            MaterialDialog.SingleButtonCallback positiveCallBack) {
        show(context, content, "取消", null, positiveText, positiveCallBack);
    }

    public static void show(Context context, String content,
                            String negativeText,
                            MaterialDialog.SingleButtonCallback negativeCallBack,
                            String positiveText,
                            MaterialDialog.SingleButtonCallback positiveCallBack) {
        show(context, content, R.color.colorPrimary,
                negativeText, R.color.colorPrimary, negativeCallBack,
                positiveText, R.color.colorPrimary, positiveCallBack,
                false);
    }

    public static void show(Context context, String content, int contentColor,
                            String negativeText, int negativeTextColor,
                            MaterialDialog.SingleButtonCallback negativeCallBack,
                            String positiveText, int positiveTextColor,
                            MaterialDialog.SingleButtonCallback positiveCallBack,
                            boolean cancelable) {

        createMaterialDialog(context, content, contentColor, negativeText, negativeTextColor,
                negativeCallBack, positiveText, positiveTextColor, positiveCallBack, cancelable)
                .show();
    }

    public static MaterialDialog createMaterialDialog(Context context, String content, int contentColor,
                                                      String negativeText, int negativeTextColor,
                                                      MaterialDialog.SingleButtonCallback negativeCallBack,
                                                      String positiveText, int positiveTextColor,
                                                      MaterialDialog.SingleButtonCallback positiveCallBack,
                                                      boolean cancelable) {
        return new MaterialDialog.Builder(context)
                //弹框内容配置
                .content(content)
                .contentColor(ContextCompat.getColor(context, contentColor))

                //左按钮配置
                .negativeText(negativeText)
                .negativeColor(ContextCompat.getColor(context, negativeTextColor))
                .onNegative(negativeCallBack)

                //右按钮配置
                .positiveColor(ContextCompat.getColor(context, positiveTextColor))
                .positiveText(positiveText)
                .onPositive(positiveCallBack)
                .cancelable(cancelable)
                .build();
    }
}
